package com.acme.faturamento.model.entity;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

/**
 * @author Reinaldo
 *
 */
@Entity
@Table(name = "cliente")
@SequenceGenerator(name = "cliente_sequence", sequenceName = "cliente_id_seq")
@TableGenerator(name = "cliente_id", table = "chaves_primarias", pkColumnName = "chave", pkColumnValue = "cliente", valueColumnName = "valor")

@NamedQuery(name="findClientes",
   query="select c from Cliente c ")
public class Cliente implements Serializable {
    private Long id;
    private String razaoSocial;
    private String cnpj;
    private String fone;
    private Collection<Endereco> enderecos;

    public String getCnpj() {
        return cnpj;
    }

    public void setCnpj(String cnpj) {
        this.cnpj = cnpj;
    }

    @OneToMany(cascade={CascadeType.ALL})
    @JoinColumn (name="CLIENTE_ID")
    public Collection<Endereco> getEnderecos() {
        return enderecos;
    }

    public void setEnderecos(Collection<Endereco> enderecos) {
        this.enderecos = enderecos;
    }

    public String getFone() {
        return fone;
    }

    public void setFone(String fone) {
        this.fone = fone;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cliente_sequence")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getRazaoSocial() {
        return razaoSocial;
    }

    public void setRazaoSocial(String razaoSocial) {
        this.razaoSocial = razaoSocial;
    }

    @Override
    public String toString() {
        return this.id+"|"+this.razaoSocial+"|"+this.cnpj+"|"+this.fone;
    }

}
